package com.tv.nextin;

import com.tv.nextin.Utils.KeyboardHelper;
import com.tv.nextin.bean.Person;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class VerifyCodeActivity extends Activity implements OnTouchListener{

	TextView title;
	ImageButton btnBack;
	TextView txtVeryfi;
	ViewGroup main;
	
	Button btnResend, btnOk;
	EditText edtVeryfi;
	Person person = new Person();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_verify_code);
		
		person = getIntent().getParcelableExtra("person");
		
		txtVeryfi = (TextView) findViewById(R.id.txt_verify);
		title = (TextView) findViewById(R.id.title);
		btnBack = (ImageButton) findViewById(R.id.btn_back);
		btnBack.setVisibility(View.VISIBLE);
		main = (ViewGroup) findViewById(R.id.main);
		KeyboardHelper.setupUI(VerifyCodeActivity.this, main);
		
		btnResend = (Button) findViewById(R.id.btn_resend);
		btnOk = (Button) findViewById(R.id.btn_next);
		edtVeryfi = (EditText) findViewById(R.id.edt_verification);
		
		
		init();
	}
	
	
	void init(){
		title.setText("Verification");
		btnBack.setOnTouchListener(this);
		btnResend.setOnTouchListener(this);
		btnOk.setOnTouchListener(this);
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		switch (v.getId()) {
		case R.id.btn_back:
			if (event.getAction() == MotionEvent.ACTION_UP){
				closeActivity();
			}
			break;
		case R.id.btn_resend:
			if (event.getAction() == MotionEvent.ACTION_UP){
				Toast.makeText(VerifyCodeActivity.this, "You resent verification!", Toast.LENGTH_SHORT).show();
			}
			break;
		case R.id.btn_next:
			if (event.getAction() == MotionEvent.ACTION_UP){
				checkVeryfiCode();
			}
			break;
		default:
			break;
		}
		return false;
	}
	
	void checkVeryfiCode(){
		if (!edtVeryfi.getText().toString().equals("")){
			gotoBookingAppoint();
		} else {
			Toast.makeText(VerifyCodeActivity.this, "Field isn't blank!", Toast.LENGTH_SHORT).show();
		}
	}
	
	void gotoBookingAppoint(){
		Intent t = new Intent(VerifyCodeActivity.this, BookingAppointmentActivity.class);
		t.putExtra("person", person);
		startActivity(t);
		overridePendingTransition(R.anim.trans_left_in, R.anim.over_main_left);
		finish();
	}
	
	void closeActivity(){
		finish();
		overridePendingTransition(R.anim.over_main_right, R.anim.trans_right_out);
	}
	
	
	@Override
	public void onBackPressed() {
		closeActivity();
	}
}
